package collection1;

import java.util.ArrayList;
import java.util.Collection;

public class CollectionOperDemo2 {
    public static void main(String[] args) {
        Collection<String> b1=new ArrayList<>();
        b1.add("java");
        b1.add("c++");
        b1.add(".net");
        System.out.println("b1:"+b1);

        Collection<String> b2=new ArrayList<>();
        b2.add("android");
        b2.add("ios");
        b2.add("java");
        System.out.println("b2:"+b2);

        //b2添加到b1中
        b1.addAll(b2);
        System.out.println("b1:"+b1);
        System.out.println("b2:"+b2);

        Collection<String> b3=new ArrayList<>();
        b3.add("c++");
        b3.add("android");
        b3.add("php");
        System.out.println("b3:"+b3);
        boolean contains2=b1.containsAll(b3);
        System.out.println(contains2);//false

        /*
        //取交集:b1中仅保留与b3所共有的元素，而b3不变
        b1.retainAll(b3);
        System.out.println("b1:"+b1);
        System.out.println("b3:"+b3);

         */
        //删除交集:将b1中与b3共有的元素删除，b3不变
        b1.removeAll(b3);
        System.out.println("b1:"+b1);
        System.out.println("b3:"+b3);
    }
}
